home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 3 / BBS in a box - Trilogy III.iso / Files / Prog / N-P / NIFTY / myCShell / text.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-12-17  |  1.9 KB  |  88 lines  |  [TEXT/KAHL]

  1. /*********************************************************
  2.  "text.c"
  3.  
  4.  by John A. Love, III [Washington Apple Pi Users' Group]
  5.  
  6.  using Symantec's "THINK C", v 5.00
  7.  *********************************************************/
  8.  
  9.  
  10. #include <Traps.h>
  11.  
  12. #include "protos"
  13.  
  14. #include "globals.h"
  15. #include "extern.h"
  16.  
  17.  
  18.  
  19.  
  20. Boolean        StylizedTE (void)    {
  21.  
  22.  
  23.     return ( TrapAvailable(_TEStyleNew) );
  24.     
  25. }    /* StylizedTE */
  26.  
  27.  
  28.  
  29. short    GetLineHeight (Boolean styleTE, TEHandle teH, short theLine)    {
  30.  
  31.  
  32.     if (styleTE)    {
  33.         if (theLine == 0)    theLine = 1;
  34.         return ( TEGetHeight(theLine, theLine, teH) );
  35.     }
  36.     else            return ( (*teH)->lineHeight );
  37.     
  38. }    /* GetLineHeight */
  39.  
  40.  
  41.  
  42. short    GetLineNbr (Boolean styleTE, TEHandle teH, short pix)    {
  43. /* Used old technique of halfing line count, instead of
  44.    adding each-and-every line's height.  Saved BIG time. */
  45.  
  46.         short    nbrLines, halfWay, currentLine;
  47.         short    linesHt = 0;        /* ... in case nbrLines = 1
  48.                                     **       AND
  49.                                     **       pix < one line's worth,
  50.                                     **       which could easily happen
  51.                                     **       using the Scroll Bar's Thumb */
  52.     nbrLines = (**teH).nLines;
  53.     if (nbrLines == 0)        return (0);
  54.     if (pix      == 0)        return (1);
  55.     
  56.     if (styleTE)    {
  57.         halfWay = nbrLines;
  58.         /* Expansion of while-loop below:
  59.         for (;;)    {
  60.             halfWay = halfWay >> 1;
  61.             if (halfWay < 1)        break;
  62.             linesHt = TEGetHeight(halfWay, 1, teH);
  63.             if (linesHt <= pix)    break;
  64.         }
  65.         */
  66.         while ( ((halfWay >>= 1) >= 1) &&
  67.                 ((linesHt = TEGetHeight(halfWay, 1, teH)) > pix) );
  68.                 
  69.         // Begin where we left off (linesHt from 1 to halfWay):
  70.         for (currentLine = halfWay+1; currentLine <= nbrLines; currentLine++)    {
  71.             linesHt += TEGetHeight(currentLine, currentLine, teH);
  72.             if (linesHt > pix)        break;
  73.         }
  74.         --currentLine;        // 1 more than real line # coming out of for-loop.
  75.         
  76.     }    /* new stylized text */
  77.     
  78.     else    /* old stuff */        currentLine = pix / (**teH).lineHeight;
  79.  
  80.     return (currentLine);
  81.     
  82. }    /* GetLineNbr */
  83.  
  84.  
  85.  
  86.  
  87. /*    { end file "text.c" }  */
  88.